#include "paths.h"
#include <OgrePlatform.h>

#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
#include <Carbon/Carbon.h>
#endif

std::string bundlePath()
{
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
	char path[1024];
	CFBundleRef mainBundle = CFBundleGetMainBundle();
	assert(mainBundle);
	
	CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle);
	assert(mainBundleURL);
	
	CFStringRef cfStringRef = CFURLCopyFileSystemPath(mainBundleURL, kCFURLPOSIXPathStyle);
	assert(cfStringRef);
	
	CFStringGetString(cfStringRef, path, 1024, kCFStringEncodingASCII);
	
	CFRelease(mainBundleURL);
	CFRelease(cfStringRef);
	
	return std::string(path);
#else
	return "";
#endif
}

std::string resourcePath()
{
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
	return bundlePath() + "/Contents/Resources/";
#else
	return bundlePath();
#endif
}
